package org.netty.push.server;

import org.netty.push.core.proto.BaseMessage;
import org.netty.push.core.proto.exception.BadDataException;
import org.netty.push.core.proto.handler.MessageHandlerManager;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class CustomerHandler extends ChannelInboundHandlerAdapter {
	
	private MessageHandlerManager messageHandlerManager;
	
	public CustomerHandler(MessageHandlerManager messageHandlerManager) {
		this.messageHandlerManager=messageHandlerManager;
	}
	/**
	 * 数据读取处理
	 */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    	if(msg instanceof BaseMessage) {
    		messageHandlerManager.handle(ctx,(BaseMessage) msg);
    	}else {
    		throw new BadDataException("");
    	}
    	
        
    }
    
    /**
     * 心跳检测处理
     */
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        ctx.fireUserEventTriggered(evt);
    }
}
